package com.cvit.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cvit.dao.ManagerMapper;
import com.cvit.model.Manager;

@Service
public class ManagerService {

	/**
	 * @author WYHY
	 * */
	@Autowired
	ManagerMapper managerMapper;
	
	/**
	 * @author WYHY
	 * @param 添加管理员
	 * */
	public int addManager(String managername,String password) {
		Manager manager=new Manager();
		SimpleDateFormat df = new SimpleDateFormat("yyyyMMddss");//设置日期格式
		int id=Integer.parseInt(df.format(new Date()));//一账户创建时间为管理员id
		manager.setId(id);
		manager.setManagername(managername);
		manager.setPassword(password);
		manager.setState(1);
		return managerMapper.insert(manager);
	}
	
	/**
	 * @author WYHY
	 * @param 删除管理员（假删）
	 * */
	public int delManagerF(String id) {
		Manager manager=managerMapper.selectByPrimaryKey(Integer.parseInt(id));
		manager.setState(0);
		return managerMapper.updateByPrimaryKey(manager);
	}
	
	/**
	 * @author WYHY
	 * @param 修改管理员
	 * */
	public int updManager(String id,String managername,String password) {
		Manager manager=managerMapper.selectByPrimaryKey(Integer.parseInt(id));
		manager.setManagername(managername);
		manager.setPassword(password);
		return managerMapper.updateByPrimaryKey(manager);
	}
	
	/**
	 * @author WYHY
	 * @param 查询所有管理员
	 * */
	public List<Manager> selAllManager() {
		List<Manager> list=managerMapper.selectAll();
		return list;
	}
	
	/**
	 * @author WYHY
	 * @param 用户名查询管理员
	 * */
	public Manager selManager(String managername) {
		Manager manager=managerMapper.selectByMnangerName(managername);
		return manager;
	}
	
	/**
	 * @author WYHY
	 * @param 查询管理员详细信息
	 * */
	public Manager selManagerA(String managerid) {
		Manager manager=managerMapper.selectByPrimaryKey(Integer.parseInt(managerid));
		return manager;
	}
}
